var bmap = require('../../../libs/bmap-wx.min.js');
Page({
    data: {
        sugData: ''
    },
	onLoad(e){
		this.setData({
			city:e.city,
			id:e.id
		})
	},
	nav(e){
		console.log(e)
		if(this.data.id==1){
			let pages = getCurrentPages(); // 当前页的数据，可以输出来看看有什么东西
			let prevPage = pages[pages.length - 2];
			prevPage.setData({
				destination:{
					map: e.currentTarget.dataset.map,
					latitude: e.currentTarget.dataset.lat,
					longitude: e.currentTarget.dataset.lng,
				}
			})
			wx.navigateBack({
				delta: 1
			})
		}else{
			let pages = getCurrentPages(); // 当前页的数据，可以输出来看看有什么东西
			let prevPage = pages[pages.length - 2];
			prevPage.setData({
				map:e.currentTarget.dataset.map,
				markers: [{
					'latitude': e.currentTarget.dataset.lat,
					'longitude': e.currentTarget.dataset.lng,
					'id': '1'
				}],
				lat1:e.currentTarget.dataset.lat,
				lng1: e.currentTarget.dataset.lng,
			})
			wx.navigateBack({
				delta: 1
			})
		}
		
	},
    bindKeyInput: function(e) {
        var that = this;
        if (e.detail.value === '') {
            that.setData({
                sugData: ''
            });
            return;
        }
        var BMap = new bmap.BMapWX({
            ak: 'GSEHM6rV9bIquAHVUuLLxYHTThvGAW5l'
        });
        var success = function(data) {
            console.log(data)
            var sugData =[];
            for(var i = 0; i < data.result.length; i++) {
                sugData.push(data.result[i])
            }
            that.setData({
                sugData: sugData
            });
        }
        BMap.suggestion({
            query: e.detail.value,
            region: this.data.city,
            city_limit: true,
            success: success
        });
    }
})